package com.jt;

import redis.clients.jedis.Jedis;

/**
 * 生成一个分布式递增的id
 * 多张表基于这个方法中生成的id
 * 作为主键的id
 * @author Administrator
 */
public class IdGeneratorDemo01 {


    public static Long getId(){
        Jedis jedis = new Jedis("192.168.126.129",6379);
        Long id = jedis.incr("id");
        jedis.close();
        return id;
    }

    public static void main(String[] args) {
        for (int i = 0; i <10 ; i++) {
            new Thread(){
                @Override
                public void run() {
                    String tName=Thread.currentThread().getName();
                    System.out.println(tName+ "->" +IdGeneratorDemo01.getId());
                }
            }.start();
        }

    }
}
